'use strict';

const BaseController = require("../base");
const PosFolderDto = require("../../dto/pos-folder.dto");
class PosFolderController extends BaseController {
  /**
  * @description 获取指定类型下所有的文件夹
  */
  async select() {
    try {
      const verifytRes = this.verifytParams(PosFolderDto.selectDto);
      if (!verifytRes.success) throw verifytRes.msg;
      const res = await this.service.ucenter.posFolder.select(verifytRes.params);
      if (!res.success) throw res.msg;
      await this.success(res.data)
    } catch (err) {
      await this.error(err);
    }
  }

  /**
    * @description 创建文件夹
    * @param {PosFolderDto.createDto} 参数
    */
  async create() {
    try {
      const verifytRes = this.verifytParams(PosFolderDto.createDto);
      if (!verifytRes.success) throw verifytRes.msg;
      const res = await this.service.ucenter.posFolder.create(verifytRes.params);
      if (!res.success) throw res.msg;
      await this.success();

    } catch (err) {
      await this.error(err);
    }
  }

  /**
   * @description 编辑
   * @param {PosFolderDto.editDto} 参数
   */
  async edit() {
    try {
      const verifytRes = this.verifytParams(PosFolderDto.editDto);
      if (!verifytRes.success) throw verifytRes.msg;
      const id = verifytRes.params.id;
      delete verifytRes.params.id;
      const res = await this.service.ucenter.posFolder.edit(id, verifytRes.params);
      if (!res.success) throw res.msg;
      await this.success();
    } catch (err) {
      await this.error(err);
    }
  }

  /**
   * @description 删除
   * @param {PosFolderDto.delDto} 参数
   */
  async del() {
    try {
      const verifytRes = this.verifytParams(PosFolderDto.delDto);
      if (!verifytRes.success) throw verifytRes.msg;
      const res = await this.service.ucenter.posFolder.del(verifytRes.params.id);
      if (!res.success) throw res.msg;
      await this.success();
    } catch (err) {
      await this.error(err);
    }
  }

}

module.exports = PosFolderController;
